class PaintingsController < ApplicationController
  def new
    @painting = Painting.new(:user_id => current_user.id)
  end

  def create
    @painting = Painting.new(:user_id => params[:user_id], :remote_image_url => params[:remote_image_url])
    if @painting.save
      flash[:notice] = "Successfully created painting."
      redirect_to :controller => :users, :action => :show_me
    else
      flash[:notice] = "Failed."
      redirect_to :controller => :users, :action => :show_me
    end
  end

  def edit
    paintings = Painting.where(:user_id => current_user.id)    
    if paintings.count == 0
      render :text => "error"
    else
      @painting = paintings[0]
    end
  end

  def update
    @painting = Painting.find_by_user_id(params[:user_id])
    if @painting.update_attributes(:user_id => params[:user_id], :remote_image_url => params[:remote_image_url])
      flash[:notice] = "Successfully created painting."
      redirect_to :controller => :users, :action => :show_me
    else
      flash[:notice] = "Failed."
      redirect_to :controller => :users, :action => :show_me
    end
  end

  # def destroy
    # @painting = Painting.find(params[:id])
    # @painting.destroy
    # flash[:notice] = "Successfully destroyed painting."
    # redirect_to :controller => :users, :action => :show_me
  # end
end
